package com.helwen.utils;

import cn.hutool.http.HttpRequest;

import java.util.Date;
import java.util.HashMap;

/**
 * @author heqiwen
 * @title: WangYiYunHttp
 * @projectName mall_qdg
 * @description: TODO
 * @date 2020/11/1410:42
 */
public class WangYiYunHttp {

    public static String callWangYiYun(String url, HashMap<String, Object> paramMap,String appKey,String appSecret,String nonce){
        Long time=(new Date()).getTime() / 1000L;
        String curTime = String.valueOf(time+1);
        String checkSum = CheckSumBuilder.getCheckSum(appSecret, nonce ,curTime);//参考 计算CheckSum的java代码

        String result = HttpRequest.post(url)
                .header("AppKey", appKey)//头信息，多个头信息多次调用此方法即可
                .header("Nonce", nonce)
                .header("CurTime", curTime)
                .header("CheckSum", checkSum)
                .header("Content-Type", "application/x-www-form-urlencoded;charset=utf-8")
                .form(paramMap)//表单内容
                .timeout(20000)//超时，毫秒
                .execute().body();
        return result;
    }
}
